@echo off
@REM SuBei rmex-lygmj 1003_40

set LocalDir=%1
set BucketName=%2
set BucketId=%3
set UpdateDir=%4
set VersionAdd=%5

@REM echo %1 %2 %3

if not defined LocalDir goto paramerror
if not defined BucketName goto paramerror
if not defined BucketId goto paramerror

if not exist %UpdateDir% (
    echo "not %UpdateDir% upload error" & exit
)
@REM 强制更新ossutil64.exe程序
@REM .\ossutil64 update -f

@REM --loglevel=info 日志
@REM -u 比对更新
@REM -f 强制上传
@REM -r 递归遍历
@REM -c 制定配置
@REM cp 上传文件
@REM if exist ossutil.log del ossutil.log exit
@REM @REM 上传更新文件
set VerFileName=%LocalDir%_version.txt
set VerFileNameAll=%LocalDir%_versionall.txt
echo "0.upload files to oss.."

if exist ./%UpdateDir%/%LocalDir%/base (
.\ossutil64 --loglevel=info -c ./config12 cp -r -f ./%UpdateDir%/%LocalDir%/base oss://%BucketName%/Download/ClientRes/%BucketId%/base/
)
if exist ./%UpdateDir%/%LocalDir%/client (
.\ossutil64 --loglevel=info -c ./config12 cp -r -f ./%UpdateDir%/%LocalDir%/client oss://%BucketName%/Download/ClientRes/%BucketId%/client/
)

if exist ./%UpdateDir%/%LocalDir%/game (
.\ossutil64 --loglevel=info -c ./config12 cp -r -f ./%UpdateDir%/%LocalDir%/game oss://%BucketName%/Download/ClientRes/%BucketId%/game/
)

if exist ./%UpdateDir%/%LocalDir%/land.zip (
.\ossutil64 --loglevel=info -c ./config12 cp -f ./%UpdateDir%/%LocalDir%/land.zip oss://%BucketName%/Download/ClientRes/%BucketId%/
)
if defined VersionAdd (

@REM version ===============================================================================================================================
echo "1.down version.txt.."
@REM 下载版本
.\ossutil64 --loglevel=info -c ./config12 cp -f oss://%BucketName%/Download/ClientRes/%BucketId%/version.txt ./version/%VerFileName%

%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -File .\version-add.ps1 ./version/%VerFileName%
if errorlevel 1 goto powershellError
if errorlevel 0 goto VersionUpload


:powershellError
echo "powershell error" & goto :eof

:VersionUpload
echo "2.version++ finish.."

@REM @REM 版本+1
.\ossutil64 --loglevel=info -c ./config12 cp -f ./version/%VerFileName% oss://%BucketName%/Download/ClientRes/%BucketId%/version.txt
echo "3.version.txt upload finish.."

@REM versionall ===============================================================================================================================
echo "1.down version.txt.."
@REM 下载版本
.\ossutil64 --loglevel=info -c ./config12 cp -f oss://%BucketName%/Download/ClientRes/%BucketId%/versionall.txt ./version/%VerFileNameAll%

%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -File .\version-add.ps1 ./version/%VerFileNameAll%
if errorlevel 1 goto powershellError
if errorlevel 0 goto VersionUpload


:powershellError
echo "powershell error" & goto :eof

:VersionUpload
echo "2.version++ finish.."

@REM @REM 版本+1
.\ossutil64 --loglevel=info -c ./config12 cp -f ./version/%VerFileNameAll% oss://%BucketName%/Download/ClientRes/%BucketId%/versionall.txt
echo "3.version.txt upload finish.."


goto :eof
)

@REM @REM 快快网络刷新缓存 

@REM call refreshCache.bat

@REM echo "refreshCache finish.."

:paramerror 
echo "version not ++ "  & goto :eof